package simulator.request;

import simulator.data.HttpData;
import java.util.ArrayList;
import java.util.concurrent.CountDownLatch;
import simulator.request.GetRequest;
import simulator.request.PostRequest;

/**
 *
 * Test
 */
public class RequestTest {
    private CountDownLatch startSignal = new CountDownLatch(1);
    private String url;
    private ArrayList<HttpData> parameters;
    private String type;
    private int total;

    public RequestTest(String url, ArrayList<HttpData> parameters, String type, int total) {
        this.url = url;
        this.parameters = parameters;
        this.type = type;
        this.total = total;
    }

    public void execute() {
        if (type.equals("GET")) {
            for (int i = 0; i < total; i++) {
                new Thread(new GetRequest(startSignal, url, parameters)).start();
            }
        } else {
            for (int i = 0; i < total; i++) {
                new Thread(new PostRequest(startSignal, url, parameters)).start();
            }
        }
        startSignal.countDown();
    }
}
